 package utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * 《一个Android工程的从零开始》
 *
 * @author 半寿翁
 * @博客：
 * @CSDN http://blog.csdn.net/u010513377/article/details/74455960
 * @简书 http://www.jianshu.com/p/1410051701fe
 */
public class TxtUtils {
    public static String getText(EditText editText) {
        return editText.getText().toString().trim();
    }

    public static String getText(TextView textText) {
        return textText.getText().toString().trim();
    }

    public static String getText(String text) {
        return TextUtils.isEmpty(text) ? "-" : text;
    }

    public static String getText(int text) {
        return TextUtils.isEmpty(String.format(Locale.CHINA, "%d", text)) ? "-" : String.format(Locale.CHINA, "%d", text);
    }

    public static String getText(long text) {
        return TextUtils.isEmpty(String.format(Locale.CHINA, "%d", text)) ? "-" : String.format(Locale.CHINA, "%d", text);
    }

    public static String getText(double text) {
        return TextUtils.isEmpty(String.format("%s", text)) ? "-" : String.format("%s", text);
    }

    public static String getText(Context context, int resourceId) {
        return context.getResources().getString(resourceId);
    }

    public static String addDate( int x)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制
        //SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制
        Date date = new Date();
//        try
//        {
//            date = format.parse(day);
//        }
//        catch (Exception ex)
//        {
//            ex.printStackTrace();
//        }
//        if (date == null) return "";
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MINUTE, x);//24小时制
        //cal.add(Calendar.HOUR, x);12小时制
        date = cal.getTime();
        System.out.println("front:" + date);
        cal = null;
        return format.format(date).substring(format.format(date).length()-8,format.format(date).length()-3);
    }


}
